function value=emp_rnd(emp_dist)

[r,c]=size(emp_dist);

n=max(r,c);

mod_emp_dist=zeros(n,1);
mod_emp_dist(1)=emp_dist(1);

ran=rand(1);

for i=1:n-1
mod_emp_dist(i+1)=mod_emp_dist(i)+emp_dist(i+1);
end

sum=0;
done=0;
k=0;

while done==0

    if k==0
       if ran<mod_emp_dist(k+1) && ran>=0
        value=k+1;
        done=1;
       else
        k=k+1;
       end
    end
    if k>0
        
        if ran<mod_emp_dist(k+1) && ran>=mod_emp_dist(k)
        value=k+1;
        done=1;
        else
        k=k+1;
        end
    end

end


end

